var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showType: 0,
    teamList: [],
    page:0,
    limit:10,
    imagesUrl:'https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4nibH0KlMECNjjGxQUq24ZEaGT4poC6icRiccVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132',
  },

  switchTab: function(event) {
    let showType = event.currentTarget.dataset.index;
    let that = this;
    that.setData({
      showType: showType,
      page:0,
      teamList:[],
      state:1,
    });
    that.getTeamList();
  },
  getTeamList() {
    // console.log(1111);return false;
    let that = this;
    let userId = wx.getStorageSync("userId");
    util.request(api.myTeam, {
      showType: that.data.showType,
      userId:userId,
      page:that.data.page,
      size:that.data.limit,
    }).then(function(res) {
      // console.log(res);return false;
      if (res.errno === 0) {
        if(res.data.length <= 0){
          that.setData({state:0});
        }
        if(res.data.length <= that.data.limit){
          that.setData({state:0});
        }
        var originteamList = that.data.teamList;
        var newteamList = originteamList.concat(res.data);
        that.setData({
          teamList: newteamList,
        })
        wx.hideLoading();
      }
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getTeamList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    wx.showNavigationBarLoading() //在标题栏中显示加载
    this.getTeamList();
    wx.hideNavigationBarLoading() //完成停止加载
    wx.stopPullDownRefresh() //停止下拉刷新
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    var self = this;
    var state = self.data.state;

    if (state > 0){
      wx.showLoading({
            title: '加载中...',
        });
        self.data.page = self.data.page + 1;
        self.getTeamList();
         wx.hideLoading();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})